package com.andy.qhb.controller.game;

import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.commons.collections.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.andy.qhb.base.RespVO;
import com.andy.qhb.controller.GameController;
import com.andy.qhb.dao.DaoUtils;
import com.andy.qhb.entity.UsrTixianLog;
import com.andy.qhb.game.GameUser;
import com.andy.qhb.utils.JsonUtils;

@Controller
@RequestMapping(value="game/api")
public class Api134Controller extends GameController{
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	/**
	 * 提现请求
	 * @param session
	 * @param data
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value="134")
	public RespVO action(HttpSession session,String data) throws Exception{
		GameUser user = getUser(session);
		Map<String, Object> reqData = JsonUtils.json2Map(data);
		long coin = MapUtils.getLongValue(reqData, "coin",0);
		if(coin < 100) {
			return RespVO.createErrorJsonResonse("提现金额必须大于等于100");
		}
		if(user.getGameInfo().getCoin() < coin) {
			return RespVO.createErrorJsonResonse("余额不足");
		}
		
		UsrTixianLog log = new UsrTixianLog();
		log.setUid(user.getId());
		log.setCoin(coin);
		log.setOrderId(System.currentTimeMillis()+"u"+user.getId());
		log.setType(1);
		log.setAcount(user.getUser().getZfb());
		log.setMethod(3);
		
		DaoUtils.insert(log);
		
		return RespVO.createSuccessJsonResonse(coin,"已经受理，请耐心等待");
		
	}
	
	
}